﻿using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace demo
{
    public class 旋转
    {
        private ExternalCommandData _commandData;

        protected readonly Document document;

        public 旋转(ExternalCommandData commandData)
        {
            _commandData = commandData;
            document = _commandData.Application.ActiveUIDocument.Document;
        }
        public void Test()
        {

            Selection selection = _commandData.Application.ActiveUIDocument.Selection;

            Reference reff = selection.PickObject(ObjectType.Element, " 选择一个墙体！");
            Element elem = document.GetElement(reff);
            Wall wall = elem as Wall;
            //创建一个旋转轴，旋转轴最好垂直于元素所在的平面
            LocationCurve lc = wall.Location as LocationCurve;
            XYZ p1 = lc.Curve.GetEndPoint(0);
            XYZ p2 = lc.Curve.GetEndPoint(1);
            Line axis = Line.CreateBound(new XYZ(p1.X, p1.Y, p1.Z + 100), p1);

            using (Transaction ts = new Transaction(document))
            {
                ts.Start("旋转");
                ElementTransformUtils.RotateElement(document, wall.Id, axis, Math.PI / 4);
                ts.Commit();
            }




        }

    }
}
